var { user } = require('../dao/index')
async function enroll(data) {
    var info = null
    if (!data.studentNumber || !data.password || !data.name) {
        info = {
            status: false,
            err: '参数错误'
        }
    } else {
        await user.find({ studentNumber: data.studentNumber }, async function (err, res) {
            if (err) {
                info = {
                    status: false,
                    err: '服务器错误'
                }
            } else {
                if (res.length != 0) {
                    info = {
                        status: false,
                        err: '用户已注册'
                    }

                } else {
                    info = {
                        status: true,
                        lay: '注册成功'
                    }
                    await user.create(data, function (err) {
                        if (err) {
                            info = {
                                status: false,
                                err: '服务器错误'
                            }
                        }
                    })
                }
            }
        })
    }
    return info
}

module.exports.enroll = enroll